define(
    [ "jquery", "application", "service", "wizard", "gegewu", "abstractPage" ],
    function($, app, serv, wizard, ggw, PlugIn) {

      function setPageCart(page, cart) {
        page.cart = cart;
        console.log("cart:" + JSON.stringify(page.cart));
        page.cart.count = page.cart.commodities.length
            + page.cart.grouppayments.length
            + page.cart.timelimitpayments.length
            + page.cart.scorepayments.length;

      }

      return (function() {
        /**
         * @param settings
         *          配置.
         * @param target
         *          直接的html对象.
         */
    	var cList;
    	serv.getCommoditiesAll(function(res){
    		cList = JSON.stringify(res);
    		console.log("cList ==" + cList);
    	});
        var clz = definePlugin("PgIndex", PlugIn, function(settings, target) {
          var self = this;
          try {
            this.initCanvas();
            this.compose();
            this.bindPageEvent();
            this.cartLoadStatus = false;
            this.addressesLoadStatus = false;
            serv.lookAtCart((function(page) {
              return (function(cart) {
                page.cartLoadStatus = true;
                setPageCart(page, cart);
                serv.loadAddresses(cart.user.openId, function(addrs) {
                  page.addressesLoadStatus = true;// @see gegewu.AddressPanel
                  page.addresses = addrs;
                  // page.addresses=[];
                });
              });
            })(this));

            serv.loadOrderHis(0, 20, (function(page) {
              return function(orderHis) {
                //console.log("orderHis:" + JSON.stringify(orderHis));
                page.orderHis = orderHis.data;
                page.orderLoadStatus = true;
              };
            })(this));
          } catch (e) {
            console.log(e);
          }
        });
        // --- function bindPageEvent
        defineFunction.call(clz.prototype, "bindPageEvent", function() {
          var page = this;
          var $page = $(page);
          
          $("body").delegate(".liTime","click",function(){
            var $this = $(this);
            var time = $this.text();
            var bgc = $this.css("background-color");
            $(".liTime").css("background-color","rgba(0,0,0,0)")
            if(bgc!="rgba(0, 0, 0, 0)"){
              time = "";
            }else{
              $this.css("background-color","lightgreen");
            }
            page.receiveDate=$("#txtDate").val();
            if(page.receiveDate==""||page.receiveDate==null||page.receiveDate==undefined){
              $("#txtDate").val($.dateUtils("format",new Date(),"YYYY-MM-DD"));
            }
            page.receiveDate=$("#txtDate").val();
            page.receiveTime=time;
            
          });
          
          $page.on("whenCommit", page.onWhenCommit);
          $page.on("afterCommit", page.onAfterCommit);
          $page.on("minusCartGoods",
              function(ev) {
                serv.addCommodities2ShoppingCart(page, ev.goods.commodityId,
                    -1, 1);
              });
          $page.on("addCartGoods", function(ev) {
            serv.addCommodities2ShoppingCart(page, ev.goods.commodityId, 1, 1);
          });
          $page.on("removeCart", function(ev) {
            // console.log(JSON.stringify(ev.goods));
            serv.removeCommoditiesFromShoppingCart(ev.goods.commodityId,
                function(cart) {
                  setPageCart(page, cart);
                });
          });
          $page.on("commitCart", function(ev) {
            // console.log("event.address:"+JSON.stringify(ev.address));
            var address = ev.address;
            var wantTime = "";
            if(serv.isBlankStr(page.receiveDate)&&serv.isBlankStr(page.receiveTime)){
              var date = new Date();
              date.setTime(date.getTime()+86400000);
              wantTime = $.dateUtils("format",date,"YYYY-MM-DD");
            }else{
              wantTime = page.receiveDate+" "+page.receiveTime
            }
            serv.commitCart(address, wantTime,function(order) {
              page.order = order;
              wizard.switch2OrderDetail(page);
            });
          });
          //20160903 为新版详细页面添加的返回首页功能
          $("body").on("switchPg00",function(){
            //self.houseKeeping();
            page.topLayer.clear();
            page.panel.clear();
            page.panel.addComp(page.header);
            page.panel.addComp(page.banner);
            // self.panel.addComp(new EmptyPanel({height:25}))
            page.panel.addComp(page.opPanel);
            page.panel.addComp(page.goods);
            page.panel.addComp(page.cupAndHead);
            page.panel.addComp(new EmptyPanel({
              height : 125
            }))
            page.panel.addComp(page.footer);
        });
          
          $("body").on("switchCart",function(){
                  var self = page;
                  self.topLayer.clear();
                  self.panel.clear();
                  self.panel.offset = 0;
                  self.panel.addComp(self.header);
                  self.panel.addComp(new EmptyPanel({
                    height : 25
                  }))
                  self.panel.addComp(self.shoppingCartOpPanel);
                  self.panel.addComp(self.cartPanel);
                  self.panel.addComp(self.cupAndHead);
                  self.panel.addComp(new EmptyPanel({
                    height : 125
                  }))
                  self.panel.addComp(self.footer);
                  self.topLayer.addComp(self.cartFooter);
                });
          
          $page.on("chgDate",function(ev){


            var self = this;
            var $html = $("<div style='position:absolute;top:0px;left:0px;width:100%;height:100%;background-color:rgba(255,255,255,0.85);z-index:0;'>&nbsp;</div>");
            $("body").css("z-index", 0);
            var $title = $("<div style='color:black;width:100%;text-align:center;font-size:36px;z-index:0;'>更换送货日期</div>");
            var $txtDate = $("<div style='color:black;' align='center'><input id='txtDate' type='date' placeholder='选择日期' style='z-index:1;width:80%;height:1.5em;font-size:24px;margin:5px;'></div>");
            
            var $txtTime = $("<div style='color:black;' align='center'>" +
            		"<ul id='ulTime'  align='center' style='list-style-type:none;float:left;width:300px;'>" +
            		//"<li class='lable' style='float:left;'>送货时段:</li>" +
            		"<li class='liTime' style='float:left;'>10:00</li><li class='liTime' style='float:left;'>11:00</li>" +
            		"<li class='liTime' style='float:left;'>12:00</li><li class='liTime' style='float:left;'>13:00</li>" +
            		"<li class='liTime' style='float:left;'>14:00</li><li class='liTime' style='float:left;'>15:00</li>" +
            		"<li class='liTime' style='float:left;'>16:00</li><li class='liTime' style='float:left;'>17:00</li>" +
            		"<li class='liTime' style='float:left;'>18:00</li><li class='liTime' style='float:left;'>19:00</li>" +
            		"<li class='liTime' style='float:left;'>20:00</li><li class='liTime' style='float:left;'>21:00</li>" +
            		"</ul></div>");

            var $bg = $("<div style='position:absolute;top:40px;left:5%;width:90%;height:8em;background-color:orange;z-index:0;'>&nbsp;</div>");
            var $txtOk = $('<a id="btnok" href="#" class="weui_btn_dialog primary" style="font-size:24px;">确定</a>');
            var $txtCancel = $('<a id="btnok" href="#" class="weui_btn_dialog default" style="font-size:24px;">取消</a>');
            $html.append($title);
            $bg.append($txtDate);
            $bg.append($txtTime);
            $html.append($bg);

            $("body").append($html);
            $bg.offset({
              top : $title.offset().top + $title.height() + 5
            });
            $bg.height($txtTime.offset().top - $bg.offset().top
                + $txtTime.outerHeight() + 50);

            $html.append($txtOk);
            $html.append($txtCancel);

            var s = ($html.width() - $txtOk.width() - $txtCancel.width()) / 3;

            $txtOk.offset({
              top : $bg.offset().top + $bg.height() - 35,
              left : s * 2 + $txtOk.width()
            });
            $txtCancel.offset({
              top : $bg.offset().top + $bg.height() - 35,
              left : s
            });

            $txtCancel.on("click", function() {
              $html.detach();
            });
            $txtOk.on("click", function() {
              var curdate = new Date();
              var date = $.dateUtils("parse",page.receiveDate+" "+page.receiveTime+":00.000");
              if(date.getTime()<(curdate.getTime())){
                page.receiveDate=undefined;
                page.receiveTime=undefined;
                alert("您选择的时间已经过去，请重新选择");
              }else if(date.getTime()<(curdate.getTime()+7200000)){//两小时间隔
                page.receiveDate=undefined;
                page.receiveTime=undefined;
                alert("无法在您希望的时间内送达，请重新选择");
              }else{
                $html.detach();
              }
            });
          });
          
          
          
          /**
           * 组装商品明细页面。
           */
          $page.on("composeGoodsDetail",function(ev){
            var self = this;
            var goods = ev.goods;
            var txt = "";
            for(var i = 0; i < goods.commoditySweetness; i++){
            	if(i == 5)break;
            	txt = txt + "*";
            }
            $.a("sync","./fn/getIgdCmd",{commodityId:goods.id},function(res){
            	self.IgdCmd = res.data;
        		console.log("lgdCmd ==" +JSON.stringify( self.IgdCmd));
        	});
            self.mainLayer.addComp(self.background);
            self.mainLayer.addComp(self.panel);
            
            self.panel.addComp(new ggw.DetailPageHeader());
            self.panel.addComp(new EmptyPanel({height:20}));
            self.panel.addComp(new ImageButton({
              image : "http://gegewu.net.cn:8080/imgs/"+goods.photo0,//TODO 修改
              top : 0,
              left : 20,
              width : 1040,
              height : 1040,
              }));
            self.panel.addComp(new EmptyPanel({height:40}));
            var line0, line1, line2, line3,line4,line5;
            line0=new GroupComponent();
            line0.addComp(new TextButton({
              text:"品名",
              top:0,
              left:40,
              fontSize:72,
              font:FONT.miaowu,
              color:"white",
              bgColor:"rgba(0,0,0,0)",
              stroke : false,
              isCenter:false
            }));
            
            line0.addComp(new TextButton({
              text:goods.name,
              top:0,
              left:(40+72)*2,
              fontSize:72,
              font:FONT.miaowu,
              color:"white",
              bgColor:"rgba(0,0,0,0)",
              stroke : false,
              isCenter:false
            }));
            
            line0.addComp(new TextButton({
              text:"￥",
              top:0,
              left:(40)*2+72*10,
              fontSize:72,
              font:FONT.miaowu,
              color:"white",
              bgColor:"rgba(0,0,0,0)",
              stroke : false,
              isCenter:false
            }));
            line0.addComp(new TextButton({
              text:$.numberUtils("format",goods.price,"0.99"),
              top:0,
              left:(40)*2+72*11,
              fontSize:72,
              font:FONT.miaowu,
              color:"white",//"#644525",
              bgColor:"rgba(0,0,0,0)",
              stroke : false,
              isCenter:false
            }));
            self.panel.addComp(line0);
            self.panel.addComp(new EmptyPanel({height:80}));
            line1=new GroupComponent();
            line1.addComp(new TextButton({
              text:"糕点信息",
              top:0,
              left:40,
              fontSize:72,
              font:FONT.miaowu,
              color:"white",
              bgColor:"rgba(0,0,0,0)",
              stroke : false,
              isCenter:false
            }));
            self.panel.addComp(line1);
            self.panel.addComp(new EmptyPanel({height:20}));
            line2=new GroupComponent();
            line2.addComp(new TextButton({
              text:"口感" + goods.commodityTextureProperty + "/" + goods.commodityTextureProperty1,
              top:0,
              left:40,
              fontSize:72,
              font:FONT.miaowu,
              color:"white",
              bgColor:"rgba(0,0,0,0)",
              stroke : false,
              isCenter:false
            }));
            self.panel.addComp(line2);
            self.panel.addComp(new EmptyPanel({height:20}));
            line3=new GroupComponent();
            line3.addComp(new TextButton({
              text:"口味" + goods.commodityTasteProperty + "/" + goods.commodityTasteProperty1,
              top:0,
              left:40,
              fontSize:72,
              font:FONT.miaowu,
              color:"white",
              bgColor:"rgba(0,0,0,0)",
              stroke : false,
              isCenter:false
            }));
            self.panel.addComp(line3);
            self.panel.addComp(new EmptyPanel({height:20}));
            line4=new GroupComponent();
            line4.addComp(new TextButton({
              
              text:"甜度 " + txt,
              top:0,
              left:40,
              fontSize:72,
              font:FONT.miaowu,
              color:"white",
              bgColor:"rgba(0,0,0,0)",
              stroke : false,
              isCenter:false
            }));
            self.panel.addComp(line4);
            self.panel.addComp(new EmptyPanel({height:80}));
            line5=new GroupComponent();
            line5.addComp(new TextButton({
              text:"格格巫的专属成分",
              top:0,
              left:40,
              fontSize:72,
              font:FONT.miaowu,
              color:"white",
              bgColor:"rgba(0,0,0,0)",
              stroke : false,
              isCenter:false
            }));
            self.panel.addComp(line5);
//xsl
            console.log("self.IgdCmd==" + self.IgdCmd);
            if(self.IgdCmd){
            	$(self.IgdCmd).each(function(i){
            		self.panel.addComp(new EmptyPanel({height:20}));
            		self.panel.addComp(new ImageButton({
            			image : "http://gegewu.net.cn:8080/imgs/"+self.IgdCmd[i].ingredientimg,//TODO 修改
            			top : 20,
            			left : 40,
            			width : 50,
            			height : 50,
            		}));
            		self.panel.addComp(new TextButton({
            			text:self.IgdCmd[i].ingredientname,
            			top:-30,
            			left:110,
            			fontSize:50,
            			font:FONT.miaowu,
            			color:"white",
            			bgColor:"rgba(0,0,0,0)",
            			stroke : false,
            			isCenter:false
            		}));
            	});
            }
//            
            self.panel.addComp(new EmptyPanel({height:220}));
            
            var op = new GroupComponent();
            op.addComp(new TextButton({
              text:"立即订购",
              top:0,
              left:1080/4,
              width:1080*4/9,
              fontSize:64,
              font:FONT.pingfangR,
              color:"white",
              bgColor:"orange",
              //stroke : true,
              isCenter:true,
              padding:10,
              radius:20,
              onClick:function(){
                serv.addCommodities2ShoppingCartAndGotoCart(page,goods.id,1,1);
              }
            }));
            op.addComp(new TextButton({
              text:"加入购物车",
              top:0,
              left:1080*3/4,
              width:1080*4/9,
              fontSize:64,
              font:FONT.pingfangR,


              color:"white",
              bgColor:"red",
              //stroke : true,
              isCenter:true,
              padding:10,
              radius:20,
              onClick:function(){
                serv.addCommodities2ShoppingCart(page,goods.id,1,1);
              }
            }));
            self.panel.addComp(op);
            //console.log(JSON.stringify(goods));
            /*最初版本 2016-09-03
            self.panel.addComp(self.header);
            self.panel.addComp(new EmptyPanel({
              height : 25
            }));
            self.panel.addComp(self.ordersOpPanel);
            self.panel.addComp(new EmptyPanel({
              height : 25
            }));
            self.goodsDetailPanel.setGoods(goods);
            self.panel.addComp(self.goodsDetailPanel);
            self.panel.addComp(new EmptyPanel({
              height : 25
            }));
            self.panel.addComp(self.cupAndHead);
            self.panel.addComp(self.footer);
            */
          });
          
          
          $page.on("composeOrder", function(ev) {
            var self = this;
            var order = ev.order;
            page.cart = undefined;
            self.orderPanel.setOrder(order);
            self.mainLayer.addComp(self.background);
            self.mainLayer.addComp(self.panel);
            self.panel.addComp(self.header);
            self.panel.addComp(new EmptyPanel({
              height : 25
            }));
            self.panel.addComp(self.ordersOpPanel);
            self.panel.addComp(new EmptyPanel({
              height : 25
            }));
            self.panel.addComp(self.orderPanel);
            self.panel.addComp(new EmptyPanel({
              height : 25
            }));
            self.panel.addComp(self.cupAndHead);
            self.panel.addComp(self.footer);
          });
          
          $page.on("composeAddressMng",function(ev){
            var self = this;
            self.houseKeeping();
            self.mainLayer.addComp(self.background);
            self.mainLayer.addComp(self.panel);
            self.panel.addComp(self.header);
            self.panel.addComp(new EmptyPanel({
              height : 25
            }))
            self.panel.addComp(self.settingsOpPanel);
            self.panel.addComp(self.addressPanel);
            self.panel.addComp(self.cupAndHead);
            // self.panel.addComp(new EmptyPanel({height:125}))
            self.panel.addComp(self.footer);
            self.topLayer.addComp(self.addressFooter);
          });
          
          $page.on("updateUserBaseInfo",function(ev){
            var self = this;
            
            serv.updateUserBaseInfo(ev.baseInfo,function(){
              self.cart.user.phone=ev.baseInfo.phone;
              self.cart.user.nickname=ev.baseInfo.nickname;
              self.settingsPanel.__preuser={};
              $("div").detach();
            });
          });
          
          //-------------
        });
        // --- function bindPageEvent end

        defineFunction.call(clz.prototype, "houseKeeping", function(ev) {
          this.ctrlLayer.clear();
          this.topLayer.clear();
          this.mainLayer.clear();
          this.panel.clear();
        });
        

        // --- function onWhenCommit
        defineFunction.call(clz.prototype, "onWhenCommit", function(ev) {
          var page = this;
          page.ctrlLayer.addComp(new ggw.ShadeTip());
        });
        // --- function onWhenCommit end
        // --- function onAfterCommit
        defineFunction.call(clz.prototype, "onAfterCommit", function(ev) {
          var page = this;
          page.ctrlLayer.clear();
          page.ctrlLayer.addComp(new ggw.ShadeTip({
            text : "购物车已更新，点击任意位置继续",
            isAppendDot : false,
            onClick : function() {
              page.ctrlLayer.clear();
            }
          }));

          setPageCart(page, ev.cart);

        });
        // --- function onAfterCommit end

        clz.prototype.panel = undefined;
        clz.prototype.header = undefined;
        clz.prototype.banner = undefined;
        clz.prototype.opPanel = undefined;
        clz.prototype.cupAndHead = undefined;
        clz.prototype.goods = undefined;
        clz.prototype.cardPanel = undefined;
        clz.prototype.footer = undefined;
        clz.prototype.orderPanel = undefined;
        clz.prototype.addressPanel = undefined;
        clz.prototype.goodsDetailPanel=undefined;
        // --- function compose()
        defineFunction.call(clz.prototype, "compose", function() {
          var self = this;
          var page = self;
          var vw = app.getLogicViewWidth();
          var vh = app.getLogicViewHeight();
          var background = new Background({
            color : "white",
            image : "./img/bg.png"
          });
          self.background = background;

          self.header = new ggw.Header({});

          self.banner = new ggw.Banner({});
          // console.log("no panel");

          self.addressPanel = new ggw.AddressPanel({});
          
          self.goodsDetailPanel=new ggw.GoodsDetailPanel({goods:{}});

          self.orderPanel = new ggw.OrderPanel({
            onClick : function() {
              // console.log("----order1:"+JSON.stringify(self.order));
              var order = self.order;
              serv.payAnOrder && (function(order) {
                serv.payAnOrder(order, function() {
                  self.order = null;
                  self.allButtons[0].onClick();// 切换到订单页面
                });
              })(order);// TODO
            }
          });

          self.cartPanel = new ggw.CartPanel();

          self.orderHisPanel = new ggw.OrderHisPanel();
          
          self.settingsPanel = new ggw.SettingsPanel();

          self.addressFooter = new ggw.AddressFooter({
            height : 100,
            backgroundColor : "rgba(0,0,0,0.7)",
            color : "white",
            onAddAddress : function(add) {
              // console.log("onAddAddress:"+JSON.stringify(add));
              serv.addAddress && (function(add) {
                serv.addAddress(add, function() {
                  $("body").find("div").detach();
                });
              })(add);
            }
          });

          self.cartFooter = new ggw.CartFooter({
            height : 300,
            backgroundColor : "rgba(0,0,0,0.7)",
            color : "white"
          });

          self.allButtons = [
              {
                label : "订单",
                icon : "iconOrder",
                onClick : function() {
                  //self.houseKeeping();
                  self.topLayer.clear();
                  self.panel.clear();
                  self.panel.addComp(self.header);
                  self.panel.addComp(new EmptyPanel({
                    height : 25
                  }));
                  self.panel.addComp(self.ordersOpPanel);

                  self.panel.addComp(self.orderHisPanel);

                  self.panel.addComp(self.cupAndHead);
                  // self.panel.addComp(new EmptyPanel({height:125}))
                  self.panel.addComp(self.footer);
                }
              },
              {
                label : function() {
                  var res = "购物车";
                  if (self.cart && $.isNumeric(self.cart.count)
                      && self.cart.count > 0) {
                    res = self.cart.count + "件商品";
                  }
                  return res;
                },
                icon : "iconShoppingCart",
                onClick : function() {
                  //self.houseKeeping();
                  self.topLayer.clear();
                  self.panel.clear();
                  self.panel.offset = 0;
                  self.panel.addComp(self.header);
                  self.panel.addComp(new EmptyPanel({
                    height : 25
                  }))
                  self.panel.addComp(self.shoppingCartOpPanel);
                  self.panel.addComp(self.cartPanel);
                  self.panel.addComp(self.cupAndHead);
                  self.panel.addComp(new EmptyPanel({
                    height : 125
                  }))
                  self.panel.addComp(self.footer);
                  self.topLayer.addComp(self.cartFooter);
                }
              }, {
                label : "设置",
                icon : "iconSettings",
                onClick : function() {
                  
                  self.topLayer.clear();
                  self.panel.clear();
                  self.panel.addComp(self.header);
                  self.panel.addComp(new EmptyPanel({
                    height : 25
                  }))
                  self.panel.addComp(self.settingsOpPanel);
                  //self.panel.addComp(self.addressPanel);
                  self.panel.addComp(self.settingsPanel);
                  self.panel.addComp(self.cupAndHead);
                  // self.panel.addComp(new EmptyPanel({height:125}))
                  self.panel.addComp(self.footer);
                  
                }
              }, {
                label : "首页",
                icon : "iconSettings",
                onClick : function() {
                  //self.houseKeeping();
                  self.topLayer.clear();
                  self.panel.clear();
                  self.panel.addComp(self.header);
                  self.panel.addComp(self.banner);
                  // self.panel.addComp(new EmptyPanel({height:25}))
                  self.panel.addComp(self.opPanel);
                  self.panel.addComp(self.goods);
                  self.panel.addComp(self.cupAndHead);
                  self.panel.addComp(new EmptyPanel({
                    height : 125
                  }))
                  self.panel.addComp(self.footer);

                }
              } ];

          self.opPanel = new ggw.OpPanel({
            buttons : [ self.allButtons[0], self.allButtons[1],
                self.allButtons[2] ]
          });
          self.settingsOpPanel = new ggw.OpPanel({
            buttons : [ self.allButtons[0], self.allButtons[3],
                self.allButtons[1] ]
          });
          self.shoppingCartOpPanel = new ggw.OpPanel({
            buttons : [ self.allButtons[0], self.allButtons[3],
                self.allButtons[2] ]
          });
          self.ordersOpPanel = new ggw.OpPanel({
            buttons : [ self.allButtons[1], self.allButtons[3],
                self.allButtons[2] ]
          });
          // console.log(JSON.stringify(background));
          /*
           * will be delete; var comp0 = new Component(); comp0.width = 100;
           * comp0.height = 50; comp0.renderComp = function(t, c) { c.fillStyle =
           * "red"; c.fillRect(0, 0, this.width, this.height); } var comp1 = new
           * Component(); comp1.top = 25; comp1.left = 50; comp1.width = 100;
           * comp1.height = 50; comp1.renderComp = function(t, c) { c.fillStyle =
           * "blue"; c.fillRect(0, 0, this.width, this.height); }
           */
          var compCup = new ImageButton({
            image : "bigcup",
            left : vw - 360,
            top : 100,
            width : 360,
            height : 780,
            onClick : function() {
            }
          });
          var compHead = new ImageButton({
            image : "bighead",
            left : -200,
            top : 0,
            width : 1000,
            height : 800,
            onClick : function() {
            }
          });
          var compBoom = new ImageButton({
            image : "boom",
            left : vw - 750,
            top : 200,
            width : 500,
            height : 395,
            onClick : function() {
            }
          });
          self.cupAndHead = new GroupComponent({
            comps : [ compHead, compCup, compBoom ]
          }); 
          
          var fnGoodsOnClick = function() {// this is goods.
            //serv.addCommodities2ShoppingCart(page, this.id, 1, 1);
            wizard.switch2GoodsDetail(page,this);
          };

          self.goods = new ggw.GoodsPanel({
            goods : [/*
                       * will be delete { id:"goods0", smallImage : "g0s", name :
                       * "杯装甜品", price : 38, onClick : fnGoodsOnClick }, {
                       * id:"goods1", smallImage : "g1s", name : "车轮泡芙", price :
                       * 25, onClick : fnGoodsOnClick } , { smallImage : "g2s",
                       * name : "脆心黑巧克力慕斯", price : 38, onClick : fnGoodsOnClick }, {
                       * smallImage : "g3s", name : "杜丝茉莉", price : 38, onClick :
                       * fnGoodsOnClick }, { smallImage : "g4s", name : "覆盆子玫瑰",
                       * price : 38, onClick : fnGoodsOnClick }, { smallImage :
                       * "g5s", name : "红丝绒", price : 20, onClick :
                       * fnGoodsOnClick }, { smallImage : "g6s", name :
                       * "开心果黑巧克力慕斯", price : 35, onClick : fnGoodsOnClick }, {
                       * smallImage : "g7s", name : "榴莲包子", price : 38, onClick :
                       * fnGoodsOnClick }, { smallImage : "g8s", name : "抹茶磅蛋糕",
                       * price : 20, onClick : fnGoodsOnClick }, { smallImage :
                       * "g9s", name : "香草慕斯", price : 30, onClick :
                       * fnGoodsOnClick }
                       */]
          });

          //加载产品
          $.a("postJsonA", "./fn/LoadCommoditiesAll", {}, function(res) {
            var data = res.data;
            $(data).each(function() {
              this.onClick = fnGoodsOnClick;
            });
            self.goods.setGoods(data);
          });

          self.footer = new ggw.Footer();

          var sp = new ScrollPanel({
            page : self,
            left : 0,
            top : 0,
            width : vw,
            height : vh
          });

          sp.addComp(self.header);
          sp.addComp(self.banner);
          sp.addComp(self.opPanel);
          sp.addComp(self.goods);

          sp.addComp(self.cupAndHead);
          sp.addComp(self.footer);
          // sp.addComp(new Banner());
          // sp.addComp(comp0);
          // sp.addComp(comp1);
          this.mainLayer.addComp(background);
          this.mainLayer.addComp(sp);
          self.panel = sp;
          // this.topLayer.addComp(new Header());
          // this.topLayer.addComp(new Footer());

          // document.write("abc<br/>")

        });

        // --- function compose() end

        return $.fn.pgIndex;
      })();
    });